package cn.bluemobi.dylan.step.di.module;


import javax.inject.Singleton;

import cn.bluemobi.dylan.step.app.App;
import cn.bluemobi.dylan.step.moder.db.DBHelper;
import cn.bluemobi.dylan.step.moder.db.RealmHelper;
import cn.bluemobi.dylan.step.moder.prefs.Prefs;
import cn.bluemobi.dylan.step.moder.prefs.SharedPreferencesHelper;
import dagger.Module;
import dagger.Provides;

/**
 * Created by $Liudan on 2018/8/7 0007.
 *
 * @Module 装载对象的容器
 */

@Module
public class AppModule {
    private final App application;

    public AppModule(App application) {
        this.application = application;
    }

    @Provides
    @Singleton
    App provideApplicationContext() {
        return application;
    }

    //提供全局的sp对象
    @Provides  //生成对象
    @Singleton
    //全局单例，在相应的component也需要添加@Singleton
    SharedPreferencesHelper provideSharedPreferences() {
//        return application.getSharedPreferences("ruihan", Context.MODE_PRIVATE);
        return new SharedPreferencesHelper(application, Prefs.prefs_name);
    }

    @Provides
    @Singleton
    DBHelper provideDBHelper(RealmHelper realmHelper) {
        return realmHelper;
    }
}
